// stencil节点的注册配置

import { Graph, Path, Curve } from '@antv/x6'
import { EType } from './config.js'

const car_width = 50
const car_height = 50


Graph.registerNode(
  EType.Car.alias,
  {
    inherit: 'rect',
    width: car_width,
    height: car_height,
    attrs: {
      body: {
        strokeWidth: 1,
        stroke: '#000',
        fill: '#31dca0',
        width: car_width,
        height: car_height,
      },
      text: {
        fontSize: 12,
        fill: '#262626',
        text: EType.Car.text
      },
    },
    markup: [
      {
        tagName: 'rect',
        selector: 'body',
      },
      {
        tagName: 'text',
        selector: 'text',
      },
    ],
    data: {
      type: EType.Car.alias
    },
  },
  true,
)

Graph.registerNode(
  EType.Export.alias,
  {
    inherit: 'rect',
    width: car_width,
    height: car_height,
    attrs: {
      body: {
        strokeWidth: 1,
        stroke: '#000',
        fill: '#037dd3',
        width: car_width,
        height: car_height,
      },
      text: {
        fontSize: 12,
        fill: '#262626',
        text: EType.Export.text
      },
    },
    markup: [
      {
        tagName: 'rect',
        selector: 'body',
      },
      {
        tagName: 'text',
        selector: 'text',
      },
    ],
    data: {
      type: EType.Export.alias
    },
  },
  true,
)

Graph.registerNode(
  EType.Entrance.alias,
  {
    inherit: 'rect',
    width: car_width,
    height: car_height,
    attrs: {
      body: {
        strokeWidth: 1,
        stroke: '#000',
        fill: '#8b459d',
        width: 50,
        height: 50,
        zIndex: -1,

      },
      body1: {
        strokeWidth: 1,
        stroke: '#000',
        fill: '#8b459d',
        refX: 0,       // 更小的X位移，确保其位于节点区域
        refY: -50,       // 更小的Y位移
        width: 50,     // 添加宽高确保显示
        height: 50,
        zIndex: -1,

      },
      polygon: {
        refY: -100,
        stroke: '#000',
        strokeWidth: 1,
        fill: '#8b459d',
        points: '0,50 50,50 50,0',
        zIndex: -1,

        // transform: 'scale(-1,1) translate(-50, 0)', // 水平翻转并移动
      },
      text: {
        text: EType.Entrance.text,
        fontSize: 12,
        fill: '#262626',
        text: EType.Entrance.text,
        refX: '50%',
        refY: '50%',
        textAnchor: 'middle',
        textVerticalAnchor: 'middle',
      },
    },
    markup: [
      {
        tagName: 'polygon',
        selector: 'polygon',
      },
      {
        tagName: 'rect',
        selector: 'body',
      },
      {
        tagName: 'rect',
        selector: 'body1',
      },
      {
        tagName: 'text',
        selector: 'text',
      },
    ],
    data: {
      type: EType.Entrance.alias
    }
  },
  true,
)

Graph.registerNode(
  EType.Electrical.alias,
  {
    inherit: 'rect',
    width: 50,
    height: 50,
    attrs: {
      body: {
        fill: '#31dca0',
        stroke: '#000',
        strokeWidth: 1,
      },
      text: {
        text: EType.Electrical.text
      },
    },
    data: {
      type: EType.Electrical.alias
    },
    ports: {
      groups: {
        a: {
          position: {
            name: 'bottom',
          },
          attrs: {
            circle: {
              magnet: true,
              fill: '#fff',
              stroke: '#000',
              strokeWidth: 1,
              r: 5,
            },
            text: {
              fill: '#666',
              fontSize: 12,
            },
          },
        },
      },
      items: [
        { group: 'a' }, // 定义一个连接桩并关联到 group 'a'
      ],
    },
    linkable: true
  },
  true,
)

Graph.registerNode(
  EType.Line.alias,
  {
    inherit: 'rect',
    width: car_width,
    height: 2,
    attrs: {
      body: {
        strokeWidth: 0,
        stroke: '#000',
        fill: '#31dca0',
        width: car_width,
        height: car_height,
      },
      text: {
        fontSize: 12,
        fill: '#ffffff',
        text: EType.Line.text,
        refY: 15,
      },
    },
    data: {
      type: EType.Line.alias,
    },
  },
  true
)

Graph.registerNode(
  EType.RoundEdge.alias,
  {
    inherit: 'rect',
    width: 50,
    height: 50,
    attrs: {
      body: {
        fill: '#31dca0',
        stroke: '#000',
        strokeWidth: 1,
      },
      text: {
        text: EType.RoundEdge.text,
      },
    },
    ports: {
      groups: {
        port1: {
          position: {
            name: 'bottom',
          },
          attrs: {
            circle: {
              fill: '#fff',
              stroke: '#000',
              strokeWidth: 1,
              r: 4,
              magnet: false,
            },
          },
        },
      },
      items: [
        { id: 'port1', group: 'port1' },
      ],
      linkable: true
    },
    data: {
      type: EType.RoundEdge.alias,
    },
  },
  true,
)

Graph.registerNode(
  EType.SmoothEdge.alias,
  {
    inherit: 'rect',
    width: 50,
    height: 50,
    attrs: {
      body: {
        fill: '#31dca0',
        stroke: '#000',
        strokeWidth: 1,
      },
      text: {
        text: EType.SmoothEdge.text,
      },
    },
    ports: {
      groups: {
        port1: {
          position: {
            name: 'bottom',
          },
          attrs: {
            circle: {
              fill: '#fff',
              stroke: '#000',
              strokeWidth: 1,
              r: 4,
              magnet: false,
            },
          },
        },
      },
      items: [
        { id: 'port1', group: 'port1' },
      ],
      linkable: true
    },
    data: {
      type: EType.SmoothEdge.alias,
    },
  },
  true,
)

Graph.registerNode(
  EType.Document.alias,
  {
    inherit: 'rect',
    width: 100,
    height: 100,
    attrs: {
      body: {
        fill: 'none',
        stroke: 'none',
      },
      label: {
        fill: '#ffffff',
        fontSize: 12,
        text: EType.Document.text,
      }
    },
    data: {
      type: EType.Document.alias,
    },
  },
  true
)

